package pdf;

import org.apache.commons.io.output.ByteArrayOutputStream;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * @author jichao
 * @date 2022/11/24 8:43
 */
public class JpgToPng {
    public static void main(String[] args) throws IOException {
        System.out.println(getBytes());
    }

    public static byte[] getBytes() throws IOException {
        ByteArrayOutputStream imgOutputStream = new ByteArrayOutputStream();
        byte[] captchaBytes;
        BufferedImage bufferedImage;
        bufferedImage = ImageIO.read(new File("C:\\Users\\PC-a\\Desktop\\nft.jpg"));

        BufferedImage newBufferedImage = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_INT_RGB);

        newBufferedImage.createGraphics().drawImage(bufferedImage, 0, 0, Color.white, null);

        ImageIO.write(newBufferedImage, "png", imgOutputStream);
        captchaBytes = imgOutputStream.toByteArray();

        return captchaBytes;
    }
}
